import requests
import re
import execjs

url = 'https://www.bjcourt.gov.cn/zxxx/indexOld.htm'

res = requests.get(url)
__jsluid_s = res.cookies.get('__jsluid_s')
print(f'__jsluid_s',__jsluid_s)

r = re.search(r'<script>document.cookie=(.*?);location.href=location.pathname\+location.search</script>', res.text,
              re.S)
if r:
    cookie_info = r.group(1)

js_str = '''
function getCookie(cookie_info){
    return eval(cookie_info)
}
'''

js_code = execjs.compile(js_str)
r = js_code.call('getCookie', cookie_info)

__jsl_clearance_s = r[18:-45]
print(f'__jsl_clearance_s   1',__jsl_clearance_s)

res2 = requests.get(url, cookies={
    '__jsluid_s': __jsluid_s,
    '__jsl_clearance_s': __jsl_clearance_s
})

r = re.search(r'<script>(.*?)</script>', res2.text, re.S)
if r:
    js_str = r.group(1)
    js_evn = '''
    var window = {
    navigator: {
        userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36'
    }
}
var document = {}
var location = {}
var setTimeout = function (callback,date){
    return callback();
}
function getCookie(){
    return document.cookie
}
    '''
    js_str = js_evn+js_str
    js_code = execjs.compile(js_str)
    r = js_code.call('getCookie')
    print(r)
